﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using V5_DBUtility;
using V5_Model;

using System.Data.OleDb;
namespace V5_DAL.SqlServer {
    public class DALProductOrder  {

        #region  BaseMethod
        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId() {
            return DbHelperSQL.GetMaxID("ID", "K_ProductOrder");
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int ID) {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from K_ProductOrder");
            strSql.Append(" where ID=" + ID);
            return DbHelperSQL.Exists(strSql.ToString());
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(ModelProductOrder model) {
            StringBuilder strSql = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();
            if (model.OrderID != null) {
                strSql1.Append("OrderID,");
                strSql2.Append("" + model.OrderID + ",");
            }
            if (model.MemberID != null) {
                strSql1.Append("MemberID,");
                strSql2.Append("" + model.MemberID + ",");
            }
            if (model.OrderTime != null) {
                strSql1.Append("OrderTime,");
                strSql2.Append("'" + model.OrderTime + "',");
            }
            if (model.ShipTime != null) {
                strSql1.Append("ShipTime,");
                strSql2.Append("'" + model.ShipTime + "',");
            }
            if (model.BuyerName != null) {
                strSql1.Append("BuyerName,");
                strSql2.Append("'" + model.BuyerName + "',");
            }
            if (model.BuyerPhone != null) {
                strSql1.Append("BuyerPhone,");
                strSql2.Append("'" + model.BuyerPhone + "',");
            }
            if (model.BuyerEmail != null) {
                strSql1.Append("BuyerEmail,");
                strSql2.Append("'" + model.BuyerEmail + "',");
            }
            if (model.BuyerAddress != null) {
                strSql1.Append("BuyerAddress,");
                strSql2.Append("'" + model.BuyerAddress + "',");
            }
            if (model.BuyerPostalcode != null) {
                strSql1.Append("BuyerPostalcode,");
                strSql2.Append("'" + model.BuyerPostalcode + "',");
            }
            if (model.ReceiverName != null) {
                strSql1.Append("ReceiverName,");
                strSql2.Append("'" + model.ReceiverName + "',");
            }
            if (model.ReceiverPhone != null) {
                strSql1.Append("ReceiverPhone,");
                strSql2.Append("'" + model.ReceiverPhone + "',");
            }
            if (model.ReceiverEmail != null) {
                strSql1.Append("ReceiverEmail,");
                strSql2.Append("'" + model.ReceiverEmail + "',");
            }
            if (model.ReceiverProCities != null) {
                strSql1.Append("ReceiverProCities,");
                strSql2.Append("'" + model.ReceiverProCities + "',");
            }
            if (model.ReceiverAddress != null) {
                strSql1.Append("ReceiverAddress,");
                strSql2.Append("'" + model.ReceiverAddress + "',");
            }
            if (model.ReceiverPostalcode != null) {
                strSql1.Append("ReceiverPostalcode,");
                strSql2.Append("'" + model.ReceiverPostalcode + "',");
            }
            if (model.Remark != null) {
                strSql1.Append("Remark,");
                strSql2.Append("'" + model.Remark + "',");
            }
            if (model.TotalPrice != null) {
                strSql1.Append("TotalPrice,");
                strSql2.Append("" + model.TotalPrice + ",");
            }
            if (model.ProductIDs != null) {
                strSql1.Append("ProductIDs,");
                strSql2.Append("'" + model.ProductIDs + "',");
            }
            if (model.ProductPrice != null) {
                strSql1.Append("ProductPrice,");
                strSql2.Append("" + model.ProductPrice + ",");
            }
            if (model.CustomItemPrice != null) {
                strSql1.Append("CustomItemPrice,");
                strSql2.Append("" + model.CustomItemPrice + ",");
            }
            if (model.Discount != null) {
                strSql1.Append("Discount,");
                strSql2.Append("'" + model.Discount + "',");
            }
            if (model.ShipPrice != null) {
                strSql1.Append("ShipPrice,");
                strSql2.Append("" + model.ShipPrice + ",");
            }
            if (model.AdvancePayment != null) {
                strSql1.Append("AdvancePayment,");
                strSql2.Append("" + model.AdvancePayment + ",");
            }
            if (model.PaymentType != null) {
                strSql1.Append("PaymentType,");
                strSql2.Append("" + model.PaymentType + ",");
            }
            if (model.ShippingType != null) {
                strSql1.Append("ShippingType,");
                strSql2.Append("" + model.ShippingType + ",");
            }
            if (model.Score != null) {
                strSql1.Append("Score,");
                strSql2.Append("" + model.Score + ",");
            }
            if (model.Weight != null) {
                strSql1.Append("Weight,");
                strSql2.Append("" + model.Weight + ",");
            }
            if (model.Quantity != null) {
                strSql1.Append("Quantity,");
                strSql2.Append("" + model.Quantity + ",");
            }
            if (model.NeedInvoice != null) {
                strSql1.Append("NeedInvoice,");
                strSql2.Append("" + model.NeedInvoice + ",");
            }
            if (model.InvoiceHead != null) {
                strSql1.Append("InvoiceHead,");
                strSql2.Append("'" + model.InvoiceHead + "',");
            }
            if (model.InvoiceContent != null) {
                strSql1.Append("InvoiceContent,");
                strSql2.Append("'" + model.InvoiceContent + "',");
            }
            if (model.IsCancelled != null) {
                strSql1.Append("IsCancelled,");
                strSql2.Append("" + model.IsCancelled + ",");
            }
            if (model.IsConfirmed != null) {
                strSql1.Append("IsConfirmed,");
                strSql2.Append("" + model.IsConfirmed + ",");
            }
            if (model.PayStatus != null) {
                strSql1.Append("PayStatus,");
                strSql2.Append("" + model.PayStatus + ",");
            }
            if (model.ShippingStatus != null) {
                strSql1.Append("ShippingStatus,");
                strSql2.Append("" + model.ShippingStatus + ",");
            }
            if (model.IsFinished != null) {
                strSql1.Append("IsFinished,");
                strSql2.Append("" + model.IsFinished + ",");
            }
            if (model.ManageHistory != null) {
                strSql1.Append("ManageHistory,");
                strSql2.Append("'" + model.ManageHistory + "',");
            }
            if (model.LastModify != null) {
                strSql1.Append("LastModify,");
                strSql2.Append("" + model.LastModify + ",");
            }
            if (model.OrderNo != null) {
                strSql1.Append("OrderNo,");
                strSql2.Append("'" + model.OrderNo + "',");
            }
            if (model.Code != null) {
                strSql1.Append("Code,");
                strSql2.Append("'" + model.Code + "',");
            }
            if (model.IsAgentF != null) {
                strSql1.Append("IsAgentF,");
                strSql2.Append("" + model.IsAgentF + ",");
            }
            if (model.IsAgentFContent != null) {
                strSql1.Append("IsAgentFContent,");
                strSql2.Append("'" + model.IsAgentFContent + "',");
            }
            if (model.IsShippingFree != null) {
                strSql1.Append("IsShippingFree,");
                strSql2.Append("" + model.IsShippingFree + ",");
            }
            strSql.Append("insert into K_ProductOrder(");
            strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
            strSql.Append(")");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(ModelProductOrder model) {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update K_ProductOrder set ");
            if (model.MemberID != null) {
                strSql.Append("MemberID=" + model.MemberID + ",");
            }
            if (model.OrderTime != null) {
                strSql.Append("OrderTime='" + model.OrderTime + "',");
            }
            if (model.ShipTime != null) {
                strSql.Append("ShipTime='" + model.ShipTime + "',");
            }
            if (model.BuyerName != null) {
                strSql.Append("BuyerName='" + model.BuyerName + "',");
            }
            if (model.BuyerPhone != null) {
                strSql.Append("BuyerPhone='" + model.BuyerPhone + "',");
            }
            if (model.BuyerEmail != null) {
                strSql.Append("BuyerEmail='" + model.BuyerEmail + "',");
            }
            if (model.BuyerAddress != null) {
                strSql.Append("BuyerAddress='" + model.BuyerAddress + "',");
            }
            if (model.BuyerPostalcode != null) {
                strSql.Append("BuyerPostalcode='" + model.BuyerPostalcode + "',");
            }
            if (model.ReceiverName != null) {
                strSql.Append("ReceiverName='" + model.ReceiverName + "',");
            }
            if (model.ReceiverPhone != null) {
                strSql.Append("ReceiverPhone='" + model.ReceiverPhone + "',");
            }
            if (model.ReceiverEmail != null) {
                strSql.Append("ReceiverEmail='" + model.ReceiverEmail + "',");
            }
            if (model.ReceiverProCities != null) {
                strSql.Append("ReceiverProCities='" + model.ReceiverProCities + "',");
            }
            if (model.ReceiverAddress != null) {
                strSql.Append("ReceiverAddress='" + model.ReceiverAddress + "',");
            }
            if (model.ReceiverPostalcode != null) {
                strSql.Append("ReceiverPostalcode='" + model.ReceiverPostalcode + "',");
            }
            if (model.Remark != null) {
                strSql.Append("Remark='" + model.Remark + "',");
            }
            if (model.TotalPrice != null) {
                strSql.Append("TotalPrice=" + model.TotalPrice + ",");
            }
            if (model.ProductIDs != null) {
                strSql.Append("ProductIDs='" + model.ProductIDs + "',");
            }
            if (model.ProductPrice != null) {
                strSql.Append("ProductPrice=" + model.ProductPrice + ",");
            }
            if (model.CustomItemPrice != null) {
                strSql.Append("CustomItemPrice=" + model.CustomItemPrice + ",");
            }
            if (model.Discount != null) {
                strSql.Append("Discount='" + model.Discount + "',");
            }
            if (model.ShipPrice != null) {
                strSql.Append("ShipPrice=" + model.ShipPrice + ",");
            }
            if (model.AdvancePayment != null) {
                strSql.Append("AdvancePayment=" + model.AdvancePayment + ",");
            }
            if (model.PaymentType != null) {
                strSql.Append("PaymentType=" + model.PaymentType + ",");
            }
            if (model.ShippingType != null) {
                strSql.Append("ShippingType=" + model.ShippingType + ",");
            }
            if (model.Score != null) {
                strSql.Append("Score=" + model.Score + ",");
            }
            if (model.Weight != null) {
                strSql.Append("Weight=" + model.Weight + ",");
            }
            if (model.Quantity != null) {
                strSql.Append("Quantity=" + model.Quantity + ",");
            }
            if (model.NeedInvoice != null) {
                strSql.Append("NeedInvoice=" + model.NeedInvoice + ",");
            }
            if (model.InvoiceHead != null) {
                strSql.Append("InvoiceHead='" + model.InvoiceHead + "',");
            }
            if (model.InvoiceContent != null) {
                strSql.Append("InvoiceContent='" + model.InvoiceContent + "',");
            }
            if (model.IsCancelled != null) {
                strSql.Append("IsCancelled=" + model.IsCancelled + ",");
            }
            if (model.IsConfirmed != null) {
                strSql.Append("IsConfirmed=" + model.IsConfirmed + ",");
            }
            if (model.PayStatus != null) {
                strSql.Append("PayStatus=" + model.PayStatus + ",");
            }
            if (model.ShippingStatus != null) {
                strSql.Append("ShippingStatus=" + model.ShippingStatus + ",");
            }
            if (model.IsFinished != null) {
                strSql.Append("IsFinished=" + model.IsFinished + ",");
            }
            if (model.ManageHistory != null) {
                strSql.Append("ManageHistory='" + model.ManageHistory + "',");
            }
            if (model.LastModify != null) {
                strSql.Append("LastModify=" + model.LastModify + ",");
            }
            if (model.OrderNo != null) {
                strSql.Append("OrderNo='" + model.OrderNo + "',");
            }
            if (model.Code != null) {
                strSql.Append("Code='" + model.Code + "',");
            }
            if (model.IsAgentF != null) {
                strSql.Append("IsAgentF=" + model.IsAgentF + ",");
            }
            if (model.IsAgentFContent != null) {
                strSql.Append("IsAgentFContent='" + model.IsAgentFContent + "',");
            }
            if (model.IsShippingFree != null) {
                strSql.Append("IsShippingFree=" + model.IsShippingFree + ",");
            }
            int n = strSql.ToString().LastIndexOf(",");
            strSql.Remove(n, 1);
            strSql.Append(" where OrderID=" + model.OrderID + " ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0) {
                return true;
            }
            else {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int ID) {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from K_ProductOrder ");
            strSql.Append(" where ID=" + ID);
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0) {
                return true;
            }
            else {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ModelProductOrder GetModel(int ID) {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * from K_ProductOrder ");
            strSql.Append(" where ID=" + ID);
            ModelProductOrder model = new ModelProductOrder();
            DataSet ds = DbHelperSQL.Query(strSql.ToString());
            if (ds != null && ds.Tables[0].Rows.Count > 0) {
                if (ds.Tables[0].Rows[0]["OrderID"] != null && ds.Tables[0].Rows[0]["OrderID"].ToString() != "") {
                    model.OrderID = int.Parse(ds.Tables[0].Rows[0]["OrderID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["MemberID"] != null && ds.Tables[0].Rows[0]["MemberID"].ToString() != "") {
                    model.MemberID = int.Parse(ds.Tables[0].Rows[0]["MemberID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["OrderTime"] != null && ds.Tables[0].Rows[0]["OrderTime"].ToString() != "") {
                    model.OrderTime = Convert.ToDateTime(ds.Tables[0].Rows[0]["OrderTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["ShipTime"] != null && ds.Tables[0].Rows[0]["ShipTime"].ToString() != "") {
                    model.ShipTime = ds.Tables[0].Rows[0]["ShipTime"].ToString();
                }
                if (ds.Tables[0].Rows[0]["BuyerName"] != null && ds.Tables[0].Rows[0]["BuyerName"].ToString() != "") {
                    model.BuyerName = ds.Tables[0].Rows[0]["BuyerName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["BuyerPhone"] != null && ds.Tables[0].Rows[0]["BuyerPhone"].ToString() != "") {
                    model.BuyerPhone = ds.Tables[0].Rows[0]["BuyerPhone"].ToString();
                }
                if (ds.Tables[0].Rows[0]["BuyerEmail"] != null && ds.Tables[0].Rows[0]["BuyerEmail"].ToString() != "") {
                    model.BuyerEmail = ds.Tables[0].Rows[0]["BuyerEmail"].ToString();
                }
                if (ds.Tables[0].Rows[0]["BuyerAddress"] != null && ds.Tables[0].Rows[0]["BuyerAddress"].ToString() != "") {
                    model.BuyerAddress = ds.Tables[0].Rows[0]["BuyerAddress"].ToString();
                }
                if (ds.Tables[0].Rows[0]["BuyerPostalcode"] != null && ds.Tables[0].Rows[0]["BuyerPostalcode"].ToString() != "") {
                    model.BuyerPostalcode = ds.Tables[0].Rows[0]["BuyerPostalcode"].ToString();
                }
                if (ds.Tables[0].Rows[0]["ReceiverName"] != null && ds.Tables[0].Rows[0]["ReceiverName"].ToString() != "") {
                    model.ReceiverName = ds.Tables[0].Rows[0]["ReceiverName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["ReceiverPhone"] != null && ds.Tables[0].Rows[0]["ReceiverPhone"].ToString() != "") {
                    model.ReceiverPhone = ds.Tables[0].Rows[0]["ReceiverPhone"].ToString();
                }
                if (ds.Tables[0].Rows[0]["ReceiverEmail"] != null && ds.Tables[0].Rows[0]["ReceiverEmail"].ToString() != "") {
                    model.ReceiverEmail = ds.Tables[0].Rows[0]["ReceiverEmail"].ToString();
                }
                if (ds.Tables[0].Rows[0]["ReceiverProCities"] != null && ds.Tables[0].Rows[0]["ReceiverProCities"].ToString() != "") {
                    model.ReceiverProCities = ds.Tables[0].Rows[0]["ReceiverProCities"].ToString();
                }
                if (ds.Tables[0].Rows[0]["ReceiverAddress"] != null && ds.Tables[0].Rows[0]["ReceiverAddress"].ToString() != "") {
                    model.ReceiverAddress = ds.Tables[0].Rows[0]["ReceiverAddress"].ToString();
                }
                if (ds.Tables[0].Rows[0]["ReceiverPostalcode"] != null && ds.Tables[0].Rows[0]["ReceiverPostalcode"].ToString() != "") {
                    model.ReceiverPostalcode = ds.Tables[0].Rows[0]["ReceiverPostalcode"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Remark"] != null && ds.Tables[0].Rows[0]["Remark"].ToString() != "") {
                    model.Remark = ds.Tables[0].Rows[0]["Remark"].ToString();
                }
                if (ds.Tables[0].Rows[0]["TotalPrice"] != null && ds.Tables[0].Rows[0]["TotalPrice"].ToString() != "") {
                    model.TotalPrice = int.Parse(ds.Tables[0].Rows[0]["TotalPrice"].ToString());
                }
                if (ds.Tables[0].Rows[0]["ProductIDs"] != null && ds.Tables[0].Rows[0]["ProductIDs"].ToString() != "") {
                    model.ProductIDs = ds.Tables[0].Rows[0]["ProductIDs"].ToString();
                }
                if (ds.Tables[0].Rows[0]["ProductPrice"] != null && ds.Tables[0].Rows[0]["ProductPrice"].ToString() != "") {
                    model.ProductPrice = int.Parse(ds.Tables[0].Rows[0]["ProductPrice"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CustomItemPrice"] != null && ds.Tables[0].Rows[0]["CustomItemPrice"].ToString() != "") {
                    model.CustomItemPrice = int.Parse(ds.Tables[0].Rows[0]["CustomItemPrice"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Discount"] != null && ds.Tables[0].Rows[0]["Discount"].ToString() != "") {
                    model.Discount = ds.Tables[0].Rows[0]["Discount"].ToString();
                }
                if (ds.Tables[0].Rows[0]["ShipPrice"] != null && ds.Tables[0].Rows[0]["ShipPrice"].ToString() != "") {
                    model.ShipPrice = int.Parse(ds.Tables[0].Rows[0]["ShipPrice"].ToString());
                }
                if (ds.Tables[0].Rows[0]["AdvancePayment"] != null && ds.Tables[0].Rows[0]["AdvancePayment"].ToString() != "") {
                    model.AdvancePayment = int.Parse(ds.Tables[0].Rows[0]["AdvancePayment"].ToString());
                }
                if (ds.Tables[0].Rows[0]["PaymentType"] != null && ds.Tables[0].Rows[0]["PaymentType"].ToString() != "") {
                    model.PaymentType = int.Parse(ds.Tables[0].Rows[0]["PaymentType"].ToString());
                }
                if (ds.Tables[0].Rows[0]["ShippingType"] != null && ds.Tables[0].Rows[0]["ShippingType"].ToString() != "") {
                    model.ShippingType = int.Parse(ds.Tables[0].Rows[0]["ShippingType"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Score"] != null && ds.Tables[0].Rows[0]["Score"].ToString() != "") {
                    model.Score = int.Parse(ds.Tables[0].Rows[0]["Score"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Weight"] != null && ds.Tables[0].Rows[0]["Weight"].ToString() != "") {
                    model.Weight = int.Parse(ds.Tables[0].Rows[0]["Weight"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Quantity"] != null && ds.Tables[0].Rows[0]["Quantity"].ToString() != "") {
                    model.Quantity = int.Parse(ds.Tables[0].Rows[0]["Quantity"].ToString());
                }
                if (ds.Tables[0].Rows[0]["NeedInvoice"] != null && ds.Tables[0].Rows[0]["NeedInvoice"].ToString() != "") {
                    model.NeedInvoice = int.Parse(ds.Tables[0].Rows[0]["NeedInvoice"].ToString());
                }
                if (ds.Tables[0].Rows[0]["InvoiceHead"] != null && ds.Tables[0].Rows[0]["InvoiceHead"].ToString() != "") {
                    model.InvoiceHead = ds.Tables[0].Rows[0]["InvoiceHead"].ToString();
                }
                if (ds.Tables[0].Rows[0]["InvoiceContent"] != null && ds.Tables[0].Rows[0]["InvoiceContent"].ToString() != "") {
                    model.InvoiceContent = ds.Tables[0].Rows[0]["InvoiceContent"].ToString();
                }
                if (ds.Tables[0].Rows[0]["IsCancelled"] != null && ds.Tables[0].Rows[0]["IsCancelled"].ToString() != "") {
                    model.IsCancelled = int.Parse(ds.Tables[0].Rows[0]["IsCancelled"].ToString());
                }
                if (ds.Tables[0].Rows[0]["IsConfirmed"] != null && ds.Tables[0].Rows[0]["IsConfirmed"].ToString() != "") {
                    model.IsConfirmed = int.Parse(ds.Tables[0].Rows[0]["IsConfirmed"].ToString());
                }
                if (ds.Tables[0].Rows[0]["PayStatus"] != null && ds.Tables[0].Rows[0]["PayStatus"].ToString() != "") {
                    model.PayStatus = int.Parse(ds.Tables[0].Rows[0]["PayStatus"].ToString());
                }
                if (ds.Tables[0].Rows[0]["ShippingStatus"] != null && ds.Tables[0].Rows[0]["ShippingStatus"].ToString() != "") {
                    model.ShippingStatus = int.Parse(ds.Tables[0].Rows[0]["ShippingStatus"].ToString());
                }
                if (ds.Tables[0].Rows[0]["IsFinished"] != null && ds.Tables[0].Rows[0]["IsFinished"].ToString() != "") {
                    model.IsFinished = int.Parse(ds.Tables[0].Rows[0]["IsFinished"].ToString());
                }
                if (ds.Tables[0].Rows[0]["ManageHistory"] != null && ds.Tables[0].Rows[0]["ManageHistory"].ToString() != "") {
                    model.ManageHistory = ds.Tables[0].Rows[0]["ManageHistory"].ToString();
                }
                if (ds.Tables[0].Rows[0]["LastModify"] != null && ds.Tables[0].Rows[0]["LastModify"].ToString() != "") {
                    model.LastModify = int.Parse(ds.Tables[0].Rows[0]["LastModify"].ToString());
                }
                if (ds.Tables[0].Rows[0]["OrderNo"] != null && ds.Tables[0].Rows[0]["OrderNo"].ToString() != "") {
                    model.OrderNo = ds.Tables[0].Rows[0]["OrderNo"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Code"] != null && ds.Tables[0].Rows[0]["Code"].ToString() != "") {
                    model.Code = ds.Tables[0].Rows[0]["Code"].ToString();
                }
                if (ds.Tables[0].Rows[0]["IsAgentF"] != null && ds.Tables[0].Rows[0]["IsAgentF"].ToString() != "") {
                    model.IsAgentF = int.Parse(ds.Tables[0].Rows[0]["IsAgentF"].ToString());
                }
                if (ds.Tables[0].Rows[0]["IsAgentFContent"] != null && ds.Tables[0].Rows[0]["IsAgentFContent"].ToString() != "") {
                    model.IsAgentFContent = ds.Tables[0].Rows[0]["IsAgentFContent"].ToString();
                }
                if (ds.Tables[0].Rows[0]["IsShippingFree"] != null && ds.Tables[0].Rows[0]["IsShippingFree"].ToString() != "") {
                    model.IsShippingFree = int.Parse(ds.Tables[0].Rows[0]["IsShippingFree"].ToString());
                }
                return model;
            }
            else {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere) {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM K_ProductOrder ");
            if (strWhere.Trim() != "") {
                strSql.Append(" where  1=1 " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }
        #endregion  Method

        #region K_ProductOrder开始
        public bool DeleteList(string IDlist) {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from K_ProductOrder ");
            strSql.Append(" where ID in (" + IDlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0) {
                return true;
            }
            else {
                return false;
            }
        }

        public DataSet GetList(int Top, string strWhere, string filedOrder) {
            return this.GetList("*", Top, strWhere, filedOrder);
        }

        public DataSet GetList(int PageSize, int PageIndex, string strWhere, string strOrder, ref int RecordCount) {
            return this.GetList("*", PageSize, PageIndex, strWhere, strOrder, ref RecordCount);
        }

        public List<ModelProductOrder> GetModelList(string strWhere) {
            DataSet ds = this.GetList(strWhere);
            if (ds != null && ds.Tables[0].Rows.Count > 0) {
                return DBCommonHelper.FillModel<ModelProductOrder>(ds);
            }
            return null;
        }

        public List<ModelProductOrder> GetModelList(int Top, string strWhere, string filedOrder) {
            DataSet ds = this.GetList(Top, strWhere, filedOrder);
            if (ds != null && ds.Tables[0].Rows.Count > 0) {
                return DBCommonHelper.FillModel<ModelProductOrder>(ds);
            }
            return null;
        }

        public List<ModelProductOrder> GetModelList(int PageSize, int PageIndex, string strWhere, string strOrder, ref int RecordCount) {
            DataSet ds = this.GetList(PageSize, PageIndex, strWhere, strOrder, ref RecordCount);
            if (ds != null && ds.Tables[0].Rows.Count > 0) {
                return DBCommonHelper.FillModel<ModelProductOrder>(ds);
            }
            return null;
        }

        public DataSet GetList(string strFiled, string strWhere) {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select " + strFiled + " ");
            strSql.Append(" FROM K_ProductOrder ");
            if (strWhere.Trim() != "") {
                strSql.Append(" where 1=1 " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        public DataSet GetList(string strFiled, int Top, string strWhere, string filedOrder) {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0) {
                strSql.Append(" Top " + Top.ToString());
            }
            strSql.Append(" " + strFiled + " ");
            strSql.Append(" FROM K_ProductOrder ");
            if (strWhere.Trim() != "") {
                strSql.Append(" where 1=1 " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        public DataSet GetList(string strFiled, int PageSize, int PageIndex, string strWhere, string strOrder, ref int RecordCount) {
            StringBuilder strSqlCount = new StringBuilder();
            strSqlCount.Append("Select Count(*) as ID From K_ProductOrder ");
            if (strWhere.Trim() != "") {
                strSqlCount.Append(" where 1=1 " + strWhere);
            }
            RecordCount = Convert.ToInt32("0" + DbHelperSQL.GetSingle(strSqlCount.ToString()));
            if (PageIndex <= 1) {
                PageIndex = 1;
            }
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select Top " + PageSize + " " + strFiled + " from K_ProductOrder where 1=1 ");
            if (strWhere.Trim() != "") {
                strSql.Append(" " + strWhere);
            }
            if (PageIndex > 1) {
                strSql.Append(" And ID Not In (Select Top " + ((PageIndex - 1) * PageSize) + " ID From K_ProductOrder Where 1=1 ");
                if (strWhere.Trim() != "") {
                    strSql.Append(" " + strWhere);
                }
                if (!string.IsNullOrEmpty(strOrder)) {
                    strSql.Append(" Order by " + strOrder);
                }
                strSql.Append(")");
            }
            if (!string.IsNullOrEmpty(strOrder)) {
                strSql.Append(" Order by " + strOrder);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }
        #endregion K_ProductOrder结束
    
    


    }
}
